package cn.lyvust.demo.shili08;

/**
 * Description:
 * date: 2021-5-11 23:02
 *
 * @author Guo_guo
 * @since JDK 1.8
 */
public class ThreadSleepDemo {
    public static void main(String[] args) {
        System.out.println("Wait");
        // 让主线程等待5秒种再执行
        Wait.bySec(5); //复习：为什么可以直接通过类而不是对象去调用bySec方法呢？
//        Wait wait = new Wait();
//        wait.bySec(5);
        System.out.println("start");
    }
}

class Wait {
    public static void bySec(long s) {
        for (int i = 0; i < s; i++) {
            System.out.println(i + 1 + "秒");
            try {
                Thread.sleep(1000); // 睡眠1秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

